package com.js.signin.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.js.signin.entity.Student;
import com.js.signin.mapper.StudentMapper;
import com.js.signin.pojo.StudentAssist;
import com.js.signin.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
@Transactional
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> selectAllIT() {
        List<Student> list = redisTemplate.opsForList().range("studentIT_key",0,-1);
        redisTemplate.expire("studentIT_key",60, TimeUnit.MINUTES);
        Integer number = Math.toIntExact(redisTemplate.opsForList().size("studentIT_key"));
        System.out.println("签到人数："+number);
        return list;
    }

    @Override
    public List<Student> selectAllJAVA() {
        List<Student> list = redisTemplate.opsForList().range("studentJAVA_key",0,-1);
        redisTemplate.expire("studentJAVA_key",60, TimeUnit.MINUTES);
        Integer number = Math.toIntExact(redisTemplate.opsForList().size("studentJAVA_key"));
        System.out.println("签到人数："+number);
        return list;
    }

    @Override
    public int SignIn(Student student) {

            if (student.getClassId()==1){
                redisTemplate.opsForList().leftPushAll("studentIT_key",student);
            }else if(student.getClassId()==2){
                redisTemplate.opsForList().leftPushAll("studentJAVA_key",student);

        }

        return 1;
    }

    @Override
    public int selectCountIT() {
        Integer number = Math.toIntExact(redisTemplate.opsForList().size("studentIT_key"));
        return number;
    }


    @Override
    public int selectCountJava() {
        Integer number = Math.toIntExact(redisTemplate.opsForList().size("studentJAVA_key"));
        return number;
    }


}
